<template>
  <div :class="className" :style="{ width: w + 'px', height: h + 'px', left: x + 'px', top: y + 'px' }">
    <!-- style -->
    <div v-html="css"></div>

    <div class="content" v-if="isShow">
      <van-notice-bar
        :scrollable="datas.scrollable"
        :wrapable = '!datas.scrollable'
        :text="text"
        :color="datas.color"
        :style="{'font-size': datas.title_size + 'px','line-height': datas.title_size + 4 + 'px'}"
        background="transparent"
      />
    </div>
  </div>
</template>

<script>
// 自定义样式
const css = function() {
  if (this.datas.color) {
    const { title_size } = this.datas;

    return `
      .component-${this.id} .content {
            font-size:${title_size}px;
        }
    `;
  }
};

export default {
  data() {
    return {
      isShow: false,
      text: ''
    };
  },
  props: ["id", "datas", "styles", "w", "h", "x", "y"],
  computed: {
    css() {
      return "<style>" + css.call(this) + "</style>";
    },
    className() {
      const name = ["component-wrapper", `component-${this.id}`];
      return name;
    }
  },
  components: {},
  methods: {
    // 获取组件数据
    async getComponentData() {
      let { result, msg, data } = await $http.post(
        "plugin.platform-screen.frontend.controllers.screen.index.get-module-data",
        {
          module_type: 9
        },
        "."
      );
      if (result == 0) return this.$toast(msg);
      this.setData(data.data);
    },
    setData(data) {
      this.isShow = false;
      this.text = data;
      this.$nextTick(() => {
        this.isShow = true;
      });
    }
  },

  mounted() {
    this.$nextTick(() => {
      this.getComponentData();
    });
  },
  destroyed() {}
};
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
.component-wrapper {
  position: absolute;
  min-width: 200px;
  min-height: 200px;
  overflow: hidden;
  padding: 0.75rem;
}
.content {
  background: linear-gradient(180deg, #050f27 0%, #0d2441 100%);
  color: #ffffff;
  overflow: hidden;
  text-align: left;
}
</style>
